package com.hospital.domain.utils;

import lombok.Data;


@Data
public class Result<T> {
    private int code;
    private String msg;
    private T data;

    public static Result<Void> ok() {
        return ok(null);
    }

    public static <T> Result<T> ok(T data) {
        return new Result<>(200, "OK", data);
    }

    public static <T> Result<T> error(String msg) {
        return new Result<>(500, msg, null);
    }

    public static <T> Result<T> fail( String msg) {
        return new Result<>(501, msg, null);
    }

    public static <T> Result<T> ok(String token, T data){
        return new Result<>(200, token, data);
    }
    public Result() {
    }

    public Result(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public boolean success(){
        return code == 200;
    }

    public boolean success(String token, T data){
        return code == 200;
    }
}
